import request from '@/utils/request';

// 统一处理响应
const handleResponse = (response) => {
  if (response.code !== 200) {
    throw new Error(response.message || '获取数据失败');
  }
  return response;
};

/**
 * 获取成绩概览
 */
export function getScoreOverview(examId, classId) {
  return request({
    url: `/api/score/overview/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取提交作业统计
 */
export function getSubmitStatistics(examId, classId) {
  return request({
    url: `/api/score/submit-statistics/${examId}`,
    method: 'get',
    params: {
        classId: classId
    }
  }).then(handleResponse);
}

/**
 * 获取作业得分表
 */
export function getScoreDetails(examId, classId) {
  return request({
    url: `/api/score/score-details/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取高频错题统计
 */
export function getErrorQuestions(examId, classId, scoreRateThreshold = 40,type) {
  return request({
    url: `/api/score/error-questions/${examId}`,
    method: 'get',
    params: { classId, scoreRateThreshold,type }
  }).then(handleResponse);
}

/**
 * 获取分数段分布
 */
export function getScoreDistribution(examId, classId, segment) {
  return request({
    url: `/api/score/score-distribution/${examId}`,
    method: 'get',
    params: {
      classId,
      segment
    }
  })
}

/**
 * 获取分数段分布表格
 */
export function getScoreDistributionTable(examId, classId) {
  return request({
    url: `/api/score/score-distribution-table/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取箱线图数据
 */
export function getBoxPlotData(examId, classId) {
  return request({
    url: `/api/score/box-plot/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取提交情况与空白率
 */
export function getSubmitDetails(examId, classId) {
  return request({
    url: `/api/score/submit-details/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取两分五率
 */
export function getScoreRates(examId, classId,gradeId,subjectId) {
  return request({
    url: `/api/score/score-rates`,
    method: 'post',
    data: {examId,classId,gradeId,subjectId}
  }).then(handleResponse);
}

/**
 * 获取学生分布数据
 */
export function getStudentDistribution(examId, classId) {
  return request({
    url: `/api/score/student-distribution/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取作业质量数据
 */
export function getHomeworkQuality(examId, classId) {
  return request({
    url: `/api/score/homework-quality/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取试题得分率数据
 */
export function getQuestionScoreRates(examId, classId) {
  return request({
    url: `/api/score/question-score-rates/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取知识点得分率数据
 */
export function getKnowlegeScoreRates(examId, classId) {
  return request({
    url: `/api/score/knowledge-score-rates/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取小题分析数据
 */
export function getQuestionAnalysis(examId, classId) {
  return request({
    url: `/api/score/question-analysis/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取客观题作答分布
 */
export function getObjectiveAnswerDistribution(examId, classId) {
  return request({
    url: `/api/score/objective-answer-distribution/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取主观题作答分布
 */
export function getSubjectiveAnswerDistribution(examId, classId) {
  return request({
    url: `/api/score/subjective-answer-distribution/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取错题分布
 */
export function getErrorDistribution(examId, classId, isSubjective) {
  return request({
    url: `/api/score/error-distribution/${examId}`,
    method: 'get',
    params: {
      classId,
      isSubjective
    }
  })
}

/**
 * 获取双向细目表
 */
export function getQuestionMatrix(examId, classId) {
  return request({
    url: `/api/score/question-matrix/${examId}`,
    method: 'get',
    params: { classId }
  }).then(handleResponse);
}

/**
 * 获取作业周/月汇总
 */
export function getHomeworkSummary(examId, classId, summaryType) {
  return request({
    url: `/api/score/homework-summary/${examId}`,
    method: 'get',
    params: {
      classId,
      summaryType
    }
  })
}

/**
 * 获取在线讲评数据
 */
export function getOnlineReview(examId, classId, questionId) {
  return request({
    url: `/api/score/online-review/${examId}`,
    method: 'get',
    params: { classId, questionId }
  }).then(handleResponse);
}

// 获取班级列表
export function getClassList(examId) {
  return request({
    url: `/api/class/list`,
    method: 'get',
    params: {
      examId
    }
  })
}

// 获取成绩波动数据
export function getRankChange(examId, classId) {
  return request({
    url: `/api/score/rank-change/${examId}`,
    method: 'get',
    params: {
      classId
    }
  })
}

// 获取空白率数据
export function getBlankRate(examId, classId) {
  return request({
    url: `/api/score/blank-rate/${examId}`,
    method: 'get',
    params: { classId }
  })
}

// 获取错题分布详情
export function getErrorDistributionDetail(examId, classId, questionId) {
  return request({
    url: `/api/score/error-distribution-detail/${examId}`,
    method: 'get',
    params: {
      classId,
      questionId
    }
  })
}

// 获取错题分布
export function getErrorquestionDetail(examId, classId, questionId) {
  return request({
    url: `/api/score/error-distribution-detail/list/${examId}`,
    method: 'get',
    params: {
      classId,
      questionId
    }
  })
}
// 月季度
export function getmothdata(examId, classId, questionId) {
  return request({
    url: `/api/score/homework-summary/${examId}`,
    method: 'get',
    params: {
      classId,
      questionId
    }
  })
}
// 下载成绩单
export function scoreDetailsExcel(examId, classId) {
  return request({
    url: `/api/score/score-details/excel/${examId}`,
    method: 'get',
    params: {
      classId,
    }
  })
}
// 多次下载成绩单
export function scoreDetailsExcels(examId, classIds) {
  return request({
    url: `/api/score/grade/score-details/excel/${examId}`,
    method: 'get',
    params: {
      classIds,
    }
  })
}
